package com.linh.location;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class BusStopOverlay extends ItemizedOverlay<OverlayItem> {

	List<BusStop> busStops;
	Context context;

	public BusStopOverlay(Context context, Drawable drawable) {
		super(boundCenterBottom(drawable));
		this.context = context;
		busStops = new ArrayList<BusStop>();
		populate();

	}

	public void setBusStops(List<BusStop> busStops) {
		this.busStops = busStops;
		populate();
	}

	@Override
	protected OverlayItem createItem(int i) {
		BusStop busStop = busStops.get(i);
		GeoPoint geoPoint = new GeoPoint(
				(int) (busStop.getLatitude() * 1000000),
				(int) (busStop.getLongitude() * 1000000));
		OverlayItem item = new OverlayItem(geoPoint, busStop.getName(),
				"Bus stop");
		return item;
	}

	@Override
	public int size() {
		return busStops.size();
	}

	@Override
	protected boolean onTap(int i) {
		BusStop busStop = busStops.get(i);
		Intent intent = new Intent();
		intent.setClassName(context, BusScheduleActivity.class.getName());
		intent.putExtra(BusStop.class.getName(), busStop);
		context.startActivity(intent);
		return true;
	}

}
